#include "component/broker/BrokerController.h"
#include "base/Uri.h"
#include "base/Define.h"

namespace zeroplus::mq
{
    BrokerController::BrokerController(const std::map<std::string, std::string> &uriMap, int brokerId)
    {
        Uri namesrvUriParser(uriMap.at("namesrvAddr"));
        Uri brokerUriParser(uriMap.at("brokerAddr"));
        Uri redisUriParser(uriMap.at("redisAddr"));
        BrokerConfig::getInstance().clientAddr = namesrvUriParser.GetUri();
        BrokerConfig::getInstance().serverAddr = brokerUriParser.GetUri();
        BrokerConfig::getInstance().publisherAddr = brokerUriParser.GetNextUri(PUSHMODE);
        BrokerConfig::getInstance().redisAddr = redisUriParser.GetUri();
        BrokerConfig::getInstance().redisHost = redisUriParser.GetIP();
        BrokerConfig::getInstance().redisPort = redisUriParser.GetPort();
        BrokerConfig::getInstance().brokerId = brokerId;

        requestProcessor_ = std::make_unique<RequestProcessor>();
        routerInfoUploader_ = std::make_unique<RouteInfoUploader>();
    }

    BrokerController::~BrokerController()
    {
        Stop();
    }

    bool BrokerController::Start()
    {
        routerInfoUploader_->Start();
        requestProcessor_->Start();
    }

    bool BrokerController::Stop()
    {
    }
}
